package sicnu.cs.ich.ich.schedule;

import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import sicnu.cs.ich.api.common.Constants;
import sicnu.cs.ich.common.services.impl.RedisService;
import sicnu.cs.ich.ich.feign.IchRankingClient;
import sicnu.cs.ich.ich.service.IIchService;

import java.util.List;

/**
 * @author CaiKe
 * @date 2021/12/9 16:59
 */
@Service
@Component
@RequiredArgsConstructor
public class IchRankingSchedule {
    private final IIchService ichService;
    private final IchRankingClient rankingClient;
    private final RedisService redisService;


    /**
     * 每天 6点到22点，每2小时触发一次
     */
    @Scheduled(cron = "0 1 6/2 * * ? ")
    public void sortIchHitRanking() throws InterruptedException {
        // 从Ich_RANKING中获取最新的热点数据
        final List<Integer> integers = rankingClient.sortAndGet();
        redisService.cacheList(Constants.REDIS_RANK_ICH_HIT, integers);
        ichService.cacheIchs(integers, 2 * 59 * 60L);
    }

}